<script>
	export default {
		onLaunch: function() {
			console.log('App Launch');
			//检测app更新
			var _this = this;

			switch (uni.getSystemInfoSync().platform) {
				case 'android':
					_this.fun_request("/Api/AppVersion/GetMainly", {}, function(res) {
						var _data = res.data;
						if (_data) {
							var version = plus.runtime.version.toString();
							var versionMainly = _data.av_version;
							var downurl = _data.av_download;
							//提示更新 
							if (version != versionMainly && version != '13.6.18') {
								plus.nativeUI.confirm("检测到新版本，是否升级？", function(e) {
									if (e.index == 0) { //下载升级包
										if (downurl.indexOf('apk') > -1) { //判断链接是apk直接下载更新
											var showLoading = plus.nativeUI.showWaiting("正在下载");
											const downloadTask = uni.downloadFile({
												url: downurl,
												success: (downloadResult) => {
													if (downloadResult.statusCode ===
														200) {
														plus.nativeUI.closeWaiting();
														console.log('安装包下载成功，即将安装：' + JSON
															.stringify(downloadResult,
																null, 4)
														);
														plus.runtime.openFile(
															downloadResult
															.tempFilePath);
													}
												}
											});
											downloadTask.onProgressUpdate((res) => {
												var prg = parseInt((parseFloat(res.totalBytesWritten) / parseFloat(res.totalBytesExpectedToWrite)) * 100);
												showLoading.setTitle("正在下载" + prg + "%");
												//uni.$emit("progress", res);
												// console.log('下载进度' + progress);
												// console.log('已经下载的数据长度' + res.totalBytesWritten);
												// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
											});
											uni.$on("cancelUpdate", () => {
												console.log("用户点击了取消下载");
												downloadTask.abort();
											});
										} else { //判断链接是url
											plus.runtime.openURL(downurl);
										}
									}
								}, "版本更新", ["升级", "以后再说"]);
							}
						}
					});
					break;
				case 'ios':
					console.log('运行iOS上');
					break;
				default:
					console.log('运行在开发者工具上');
					break;
			}

		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "./static/common.css";
	/* 加载框架核心样式 */
	@import "./GraceUI5/css/graceUI.css";
	/* 加载主题样式 */
	@import "./GraceUI5/skin/black.css";
	@import "./uni_modules/uview-ui/index.scss";

	/* 加载图标字体 - 条件编译模式 */
	/* #ifdef APP-PLUS-NVUE */
	.gui-icons {
		font-family: graceIconfont;
	}

	/* #endif */
</style>
